package com.njts.Polymorphism;

/**
 * @author David GE
 * Date  2025/11/20
 * 定义银行卡：主卡和副卡类，完成下列功能
 * 1、完成银行卡-主卡的存取款方法
 *   主卡卡有余额，卡号，户主等属性
 *   有存款和取款的方法（取款时候余额不足要有提示）
 * 2、完成银行卡-副卡的取款方法
 *   副卡额外有透支额度属性(副卡可用主卡中余额，且余额不够，可以透支额度)
 *   副卡重写取款方法（取款时候余额不足要有提示）
 * 3、写测试案例，分别测试主卡和副卡的存取款功能（存取款后显示余额）
 */
public class CreditCard {
    private double balance;
    private String number;
    private String account;

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }
    public double save(double money){
        this.balance=this.balance+money;
        System.out.println("成功存入"+money+"元");
        return this.balance;
    }
    public double withdraw(double money){
        // 判断主卡中的余额是否充足
        if (money<=this.balance){
            this.balance=this.balance-money;
            System.out.println("取款成功,余额为"+balance+"元");
        }else{
            System.out.println("余额不足,取款失败");
        }
        return this.balance;
    }
}

class ViceCreditCard extends CreditCard {


    private double share;

    public double getShare() {
        return share;
    }

    public void setShare(double share) {
        this.share = share;
    }

    public double withdraw(double money){
        // 主卡余额充足
        if (money<=this.getBalance()){
          this.setBalance(this.getBalance()-money);
            System.out.println("取款成功"+money+"元");
        }
        // 主卡余额不足,在额度内
        else if (money<=(this.getBalance()+this.share)){
            double balance = this.getBalance();
            money-=balance;
            this.setBalance(0.0);
            this.share=this.share-money;
            System.out.println("余额不足,您已透支"+money+"元");

        }
        else {
            // 超额
            System.out.println("取款失败,您的透支额度已达上限,请确认您的取款额为"+money+"元?");
        }
        return this.getBalance();
    }
}
